home *** CD-ROM | disk | FTP | other *** search
/ Super Shareware Collection / Super Shareware Collection.iso / os_2 / memsz220.zip / CONFIG.CPP < prev    next >
C/C++ Source or Header  |  1994-02-07  |  9KB  |  268 lines

  1. /****************************************************************** CONFIG.CC
  2.  *                                        *
  3.  *              Clock Configuration Dialog                *
  4.  *                                        *
  5.  ****************************************************************************/
  6.  
  7. #define INCL_PM
  8. #define INCL_WINSTDSPIN
  9. #include <os2.h>
  10.  
  11. #include <stdlib.h>
  12. #include <string.h>
  13.  
  14. #include "debug.h"
  15. #include "support.h"
  16.  
  17. #include "memsize.h"
  18. #include "config.h"
  19.  
  20.  
  21. /****************************************************************************
  22.  *                                        *
  23.  *               Definitions & Declarations                *
  24.  *                                        *
  25.  ****************************************************************************/
  26.  
  27.   // Function Prototypes
  28.  
  29. static METHODFUNCTION InitDlg ;
  30. static METHODFUNCTION Command ;
  31. static METHODFUNCTION OK ;
  32. static METHODFUNCTION Cancel ;
  33.  
  34.  
  35. /****************************************************************************
  36.  *                                        *
  37.  *    "Configure" Dialog Processor                        *
  38.  *                                        *
  39.  ****************************************************************************/
  40.  
  41. extern MRESULT EXPENTRY ConfigureProcessor
  42. (
  43.   HWND hwnd,
  44.   USHORT msg,
  45.   MPARAM mp1,
  46.   MPARAM mp2
  47. )
  48. {
  49.  /***************************************************************************
  50.   *                Declarations                    *
  51.   ***************************************************************************/
  52.  
  53.   static METHOD Methods [] =
  54.   {
  55.     { WM_INITDLG, InitDlg },
  56.     { WM_COMMAND, Command }
  57.   } ;
  58.  
  59.  /***************************************************************************
  60.   * Dispatch the message according to the method table and return the        *
  61.   *   result.  Any messages not defined above get handled by the system     *
  62.   *   default dialog processor.                         *
  63.   ***************************************************************************/
  64.  
  65.   return ( DispatchMessage ( hwnd, msg, mp1, mp2, Methods, sizeof(Methods)/sizeof(Methods[0]), WinDefDlgProc ) ) ;
  66. }
  67.  
  68. /****************************************************************************
  69.  *                                        *
  70.  *    Initialize Dialog                            *
  71.  *                                        *
  72.  ****************************************************************************/
  73.  
  74. static MRESULT APIENTRY InitDlg
  75.   HWND hwnd, 
  76.   USHORT msg,
  77.   MPARAM mp1, 
  78.   MPARAM mp2
  79. )
  80. {
  81.  /***************************************************************************
  82.   * Get initial parameters.                            *
  83.   ***************************************************************************/
  84.  
  85.   PCONFIG_PARMS Parms = (PCONFIG_PARMS) ( PVOIDFROMMP ( mp2 ) ) ;
  86.  
  87.   WinSetWindowPtr ( hwnd, QWL_USER, Parms ) ;
  88.  
  89.  /***************************************************************************
  90.   * Associate the help instance.                        *
  91.   ***************************************************************************/
  92.  
  93.   WinSetWindowUShort ( hwnd, QWS_ID, Parms->id ) ;
  94.  
  95.   if ( Parms->hwndHelp )
  96.   {
  97.     WinAssociateHelpInstance ( Parms->hwndHelp, hwnd ) ;
  98.   }
  99.  
  100.  /***************************************************************************
  101.   * Load the list box.                                *
  102.   ***************************************************************************/
  103.  
  104.   for ( int i=0; i<Parms->ItemCount; i++ )
  105.   {
  106.     WinSendDlgItemMsg ( hwnd, IDD_CONFIG_ITEMS, LM_INSERTITEM,
  107.       MPFROMSHORT(LIT_END), MPFROMP(Parms->ItemNames[i]) ) ;
  108.  
  109.     if ( Parms->ItemFlags[i] )
  110.     {
  111.       WinSendDlgItemMsg ( hwnd, IDD_CONFIG_ITEMS, LM_SELECTITEM,
  112.     MPFROMSHORT(SHORT(i)), MPFROMSHORT(TRUE) ) ;
  113.     }
  114.   }
  115.  
  116.  /***************************************************************************
  117.   * Set the radio button and checkbox values.                    *
  118.   ***************************************************************************/
  119.  
  120.   WinSendDlgItemMsg ( hwnd, IDD_CONFIG_HIDECONTROLS,
  121.     BM_SETCHECK, MPFROMSHORT(Parms->HideControls), 0 ) ;
  122.  
  123.   WinSendDlgItemMsg ( hwnd, IDD_CONFIG_FLOAT,
  124.     BM_SETCHECK, MPFROMSHORT(Parms->Float), 0 ) ;
  125.  
  126.  /***************************************************************************
  127.   * Set the limits and initial value of the spin-button control.        *
  128.   ***************************************************************************/
  129.  
  130.   WinSendDlgItemMsg ( hwnd, IDD_CONFIG_TIMER,
  131.     SPBM_SETLIMITS, (MPARAM)300L, (MPARAM)10L ) ;
  132.  
  133.   WinSendDlgItemMsg ( hwnd, IDD_CONFIG_TIMER,
  134.     SPBM_SETCURRENTVALUE, (MPARAM)(Parms->TimerInterval/100), NULL ) ;
  135.  
  136.  /***************************************************************************
  137.   * Return without error.                            *
  138.   ***************************************************************************/
  139.  
  140.   return ( MRFROMSHORT ( FALSE ) ) ;
  141. }
  142.  
  143. /****************************************************************************
  144.  *                                        *
  145.  *    Process commands received by the Configure Dialog            *
  146.  *                                        *
  147.  ****************************************************************************/
  148.  
  149. static MRESULT APIENTRY Command
  150.   HWND hwnd, 
  151.   USHORT msg, 
  152.   MPARAM mp1, 
  153.   MPARAM mp2
  154. )
  155. {
  156.  /***************************************************************************
  157.   * Local Declarations                                *
  158.   ***************************************************************************/
  159.  
  160.   static METHOD Methods [] =
  161.   {
  162.     { DID_OK,      OK     },
  163.     { DID_CANCEL, Cancel },
  164.   } ;
  165.  
  166.  /***************************************************************************
  167.   * Dispatch the message without a default message processor.            *
  168.   ***************************************************************************/
  169.  
  170.   return ( DispatchMessage ( hwnd, SHORT1FROMMP(mp1), mp1, mp2, Methods, sizeof(Methods)/sizeof(Methods[0]), NULL ) ) ;
  171. }
  172.  
  173. /****************************************************************************
  174.  *                                        *
  175.  *    Process the Configure Dialog's OK button being pressed.             *
  176.  *                                        *
  177.  ****************************************************************************/
  178.  
  179. static MRESULT APIENTRY OK
  180.   HWND hwnd, 
  181.   USHORT msg, 
  182.   MPARAM mp1, 
  183.   MPARAM mp2
  184. )
  185. {
  186.  /***************************************************************************
  187.   * Find the instance data.                            *
  188.   ***************************************************************************/
  189.  
  190.   PCONFIG_PARMS Parms = PCONFIG_PARMS ( WinQueryWindowPtr ( hwnd, QWL_USER ) ) ;
  191.  
  192.  /***************************************************************************
  193.   * Query the list box items for their selection.                *
  194.   ***************************************************************************/
  195.  
  196.   for ( int i=0; i<Parms->ItemCount; i++ )
  197.   {
  198.     Parms->ItemFlags[i] = FALSE ;
  199.   }
  200.  
  201.   SHORT Selection = LIT_FIRST ;
  202.   do
  203.   {
  204.     Selection = BOOL ( SHORT1FROMMR ( WinSendDlgItemMsg ( hwnd,
  205.       IDD_CONFIG_ITEMS, LM_QUERYSELECTION,
  206.       MPFROMSHORT(SHORT(Selection)), 0 ) ) ) ;
  207.  
  208.     if ( Selection != LIT_NONE )
  209.     {
  210.       Parms->ItemFlags[Selection] = TRUE ;
  211.     }
  212.   }
  213.   while ( Selection != LIT_NONE ) ;
  214.  
  215.  /***************************************************************************
  216.   * Query the buttons for their new settings.                    *
  217.   ***************************************************************************/
  218.  
  219.   Parms->HideControls = (BOOL) SHORT1FROMMR ( WinSendDlgItemMsg ( hwnd,
  220.     IDD_CONFIG_HIDECONTROLS, BM_QUERYCHECK, 0L, 0L ) ) ;
  221.  
  222.   Parms->Float = (BOOL) SHORT1FROMMR ( WinSendDlgItemMsg ( hwnd,
  223.     IDD_CONFIG_FLOAT, BM_QUERYCHECK, 0L, 0L ) ) ;
  224.  
  225.  /***************************************************************************
  226.   * Query the spinbuttons for their new settings.                *
  227.   ***************************************************************************/
  228.  
  229.   WinSendDlgItemMsg ( hwnd, IDD_CONFIG_TIMER, SPBM_QUERYVALUE,
  230.     &Parms->TimerInterval, MPFROM2SHORT(NULL,SPBQ_UPDATEIFVALID) ) ;
  231.  
  232.   Parms->TimerInterval *= 100 ;
  233.  
  234.  /***************************************************************************
  235.   * Dismiss the dialog with a TRUE status.                    *
  236.   ***************************************************************************/
  237.  
  238.   WinDismissDlg ( hwnd, TRUE ) ;
  239.  
  240.   return ( 0 ) ;
  241. }
  242.  
  243. /****************************************************************************
  244.  *                                        *
  245.  *    Process the Configure Dialog's being cancelled.                     *
  246.  *                                        *
  247.  ****************************************************************************/
  248.  
  249. static MRESULT APIENTRY Cancel
  250.   HWND hwnd, 
  251.   USHORT msg, 
  252.   MPARAM mp1, 
  253.   MPARAM mp2
  254. )
  255. {
  256.  /***************************************************************************
  257.   * Dismiss the dialog with a TRUE status.                    *
  258.   ***************************************************************************/
  259.  
  260.   WinDismissDlg ( hwnd, FALSE ) ;
  261.  
  262.   return ( 0 ) ;
  263. }
  264.